package com.lindroy.androidplayer.viewmodels

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import androidx.paging.PagingData
import androidx.paging.cachedIn
import com.lindroy.androidplayer.logic.model.ArticleResp
import com.lindroy.androidplayer.logic.network.repository.Repository
import com.lindroy.androidplayer.utils.mapArticleData
import com.lindroy.androidplayer.utils.mapSingle
import kotlinx.coroutines.flow.Flow

/**
 * @author Lin
 * @date 2022/1/26
 * @function 广场
 */
class SquareViewModel : PageViewModel() {

    private val articleItemClickAction = MutableLiveData<ArticleItemViewModel>()

    val articleItemClickLiveData  = articleItemClickAction.mapSingle { it }

    val squareArticles: Flow<PagingData<ArticleItemViewModel>>
        get() = Repository.squareArticles.mapArticleData(articleItemClickAction).cachedIn(viewModelScope)

}